package com.lm.security.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * @author lm_jcf
 * @date 2018/4/26 18:02
 * callable 实现异步调用：
 *  必须由主线程发起
 */
@RestController
public class AsyncController {

    private Logger logger = LoggerFactory.getLogger(AsyncController.class);

    @RequestMapping("/call")
    public Callable<String> runAsync(){
        logger.info("主线程开始");
        Callable<String> result = new Callable<String>() {
            @Override
            public String call() throws Exception {
                logger.info("副线程开始");
                Thread.sleep(500);
                logger.info("副线程结束");
                return "ok";
            }
        };
        logger.info("主线程结束");

        return result;
    }

}